package com.example.abc.web;

import com.example.abc.common.Constants;
import com.example.abc.dto.MyUserDetails;
import com.example.abc.entity.Account;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;

/**
 * Created by Peter on 2018/4/23.
 */
@Controller
public class IndexController {
    public static final Logger logger = LoggerFactory.getLogger(IndexController.class);


    @RequestMapping(value = "/", method = {RequestMethod.GET})
    public String index(Model model) {
        MyUserDetails account = (MyUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        logger.info("index");
        model.addAttribute("username", account.getUsername());
        model.addAttribute("real_name", account.getReal_name());
        model.addAttribute("avatar_url", account.getAvatar_url());
        model.addAttribute("websocketUrl", Constants.websocketUrl);
        logger.info(Constants.websocketUrl);
        return "index";
    }

    @RequestMapping(value = "/dashboard", method = {RequestMethod.GET})
    public String dashboard(Model model) {
        return "dashboard";
    }
}
